AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )

include( 'shared.lua' )

function GM:PlayerDeath(victim)
	e=ents.Create("sent_gift")	//Hopefully, make a gift at a death mans body
	e:SetPos(victim:GetPos())	
/*	e:Spawn()
	e:Wake()
	e:Activate()*/
end

// Serverside only stuff goes here

function GM:PlayerInitialSpawn(pl)
	pl:SetTeam(1)
	umsg.Start("call_vgui", ply)
	umsg.End()
	pl:SetModel( "models/Jaanus/santa.mdl" )
end
/*---------------------------------------------------------
   Name: gamemode:PlayerLoadout( )
   Desc: Give the player the default spawning weapons/ammo
---------------------------------------------------------*/


function GM:PlayerLoadout( pl )
	
	pl:Give( "real_snowball_swep" )
//	pl:Give( "melon_thrower" )	//Default: its a gift! :D
end

function GM:PlayerSpawn(ply)
	ply:SetModel( "models/Jaanus/santa.mdl" )
//	ply:SetColor( team.GetColor(ply:Team()))
	ply:Give( "real_snowball_swep" )
//	pl:Give( "melon_thrower" )	//Default: its a gift! :D
	if ply:Team()==1 then ply:SetColor(255,255,255,255) end
	if ply:Team()==2 then ply:SetColor(255, 100, 100, 255) end
	if ply:Team()==3 then ply:SetColor(0, 255, 64, 255) end
	if ply:Team()==4 then ply:SetColor(0, 255, 255, 255) end	//Fixme: find automatic teamcolor!
end

function ISaid( ply, text, team, death )	//Extract from wiki - takes the text a player write, if first word is "team" (dont care about size) then it put him into the team he write (if it exist). And some admin-functions.
    tT=string.Explode(" ", text)
	if tostring(tT[1]) == "team" then
		if tT[2]!=nil then
			if tT[2]=="1" or tostring(string.lower(tT[2]))=="white" then ply:SetTeam(1) end
			if tT[2]=="2" or tostring(string.lower(tT[2]))=="red" then ply:SetTeam(2) end
			if tT[2]=="3" or tostring(string.lower(tT[2]))=="green" then ply:SetTeam(3) end
			if tT[2]=="4" or tostring(string.lower(tT[2]))=="blue" then ply:SetTeam(4) end
		else
			ply:ConCommand("team")
		end
	else
		if ply:IsAdmin() or ply:IsUserGroup("admin") or ply:IsSuperAdmin() or ply:IsUserGroup("superadmin") then
			if tostring(tT[1])=="!kick" and tonumber(tT[2])!=nil then 
				RunConsoleCommand("kickid", tT[2], "You were kicked by a admin!")
			end
		else
			Msg("YOU'RE NOT A ADMIN!!!\n Omfg,omfg,omfg...\n")
		end
	end
end
hook.Add( "PlayerSay", "ISaid", ISaid );


function GM:PlayerSelectSpawn( pl ) //Extract from somewere
 
    local spawns = ents.FindByClass( "info_player_start" )
    local random_entry = math.random(#spawns)
 
    return spawns[random_entry]
 
end
